﻿using System;
using T.FAS.Runtime.Action.SPI;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.Metadata.Entity.DataModel;

namespace T.FAS.Runtime.Action.Common
{
    public class TSchemaConverter
    {
        public static TSchema ConvertToTSchema(TSchemaConvertType tsType, string metadataID)
        {
            TSchema schema = null;
            switch (tsType)
            {
                case TSchemaConvertType.CDO:
                    {
                        var cdo = new T.FAS.Runtime.DataModel.Plugin.CompositeDataObjectManager().GetMetaDataContent(metadataID) as CompositeDataObject;
                        schema = cdo.BuildSchema();
                    }
                    break;
                case TSchemaConvertType.EO:
                    {
                        var eo = new T.FAS.Runtime.DataModel.Plugin.EntityObjectManager().GetMetaDataContent(metadataID) as EntityObject;
                        schema = eo.BuildSchema();
                    }
                    break;
                case TSchemaConvertType.DQ:
                    {
                        var dq = new T.FAS.Runtime.DataModel.Plugin.DataQueryRTPManager().GetMetaDataContent(metadataID) as DataQuery;
                        schema = dq.BuildSchema();
                    }
                    break;
                default:
                    throw new Exception("Unknow Type Convert To TSchema");
            }
            return schema;
        }

        private static ITSchemaBuilder CreateBuilder(TSchemaConvertType tsType)
        {
            ITSchemaBuilder builder = null;
            switch (tsType)
            {
                case TSchemaConvertType.CDO:
                    break;
                case TSchemaConvertType.EO:
                default:
                    builder = default;
                    break;
            }
            if (builder == null)
                builder = new DefaultTSchemaBuilder();
            return builder;
        }
    }
}
